#{extends 'template/main.html' /}
#{set title:'areaNutri' /}

<fieldset>
<legend><span class="glyphicon glyphicon-user"></span> Área do Nutricionista</legend>

<div id="botoesMenu">
	<ul class="nav navbar-nav navbar-right">
		<li><a data-toggle="modal" href="@{Pacientes.form()}"><button type="submit" class="btn btn-success btn-sm" title="Adicionar Nutricionista">
				<span class="glyphicon glyphicon-plus"></span> Adicionar Paciente
			</button></a>
		</li>
		<li><a data-toggle="modal"  data-target="#mmmyModal"><button type="submit" class="btn btn-success btn-sm" title="Calcular IMC">
				<span class="glyphicon glyphicon-wrench"></span> Calcular IMC
			</button></a>		
	</ul>
</div>

<div class="panel panel-success">
  <div class="panel-heading">
  	<h4><span class="glyphicon glyphicon-list-alt"></span> Pacientes</h4>
  </div>
  <div class="panel-body">
  	#{if !pacientes.empty}
<table class="table table-striped">
				<thead>
					<tr>
						<th>Nome</th>
						<th>CPF</th>
						<th>Telefone</th>
						<th>Celular</th>
						<th>Email</th>				
						<th>Ações</th>
					</tr>
				</thead>
				<tbody>
					#{list items:pacientes, as: 'paciente'}
					<tr>
						<td>${paciente.nome}</td>
						<td>${paciente.cpf}</td>						
						<td>${paciente.telefone}</td>
						<td>${paciente.celular}</td>
						<td>${paciente.email}</td>
						<td><a data-toggle="modal" href="@{pacientes.show(paciente.id)}"
							class="glyphicon glyphicon-edit" title="Editar"></a>
							<a href="@{pacientes.excluir(paciente.id)}"
							class="glyphicon glyphicon-trash" title="Excluir"  onclick="return confirm('Tem certeza que deseja excluir?')"></a>
							</td>
					</tr>
					#{/list}
				</tbody>
			</table>
			#{/if}
  </div>
</div>


			</fieldset>
		
<div class="modal fade" id="mmyModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">Novo Paciente</h4>
        </div>
        <form class="form-horizontal" role="form" action="@{Pacientes.salvar()}">
        <div class="modal-body">
         	
         		<div class="form-group">
			    <label for="inputNome1" class="col-lg-2 control-label">Nome</label>
			    <span class="error">#{error 'paciente.nome' /}</span>
			    <div class="col-lg-10">
			      <input type="text" class="form-control" id="inputNome1" name="paciente.nome" placeholder="Nome" value="${flash['paciente.nome']}">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="inputCpf1" class="col-lg-2 control-label">CPF</label>
			    <div class="col-lg-10">
			      <input type="text" class="form-control" id="inputCpf1" name="paciente.cpf"  placeholder="CPF" value="${flash['paciente.cpf']}">
			    </div>
  			</div>
  			<div class="form-group">
			    <label for="inputTelefone1" class="col-lg-2 control-label">Telefone</label>
			    <div class="col-lg-10">
			      <input type="text" class="form-control" id="inputTelefone1" name="paciente.telefone"  placeholder="Telefone" value="${flash['paciente.telefone']}">
			    </div>
  			</div>
  			<div class="form-group">
			    <label for="inputCelular1" class="col-lg-2 control-label">Celular</label>
			    <div class="col-lg-10">
			      <input type="text" class="form-control" id="inputCpf1" name="paciente.celular"  placeholder="Celular" value="${flash['paciente.celular']}">
			    </div>
  			</div>
  			<div class="form-group">
			    <label for="inputEmail1" class="col-lg-2 control-label">Email</label>
			    <div class="col-lg-10">
			      <input type="text" class="form-control" id="inputEmail1" name="paciente.email"  placeholder="Email" value="${flash['paciente.email']}">
			    </div>
  			</div>
  			<div class="form-group">
			    <label for="inputCrn1" class="col-lg-2 control-label">Endereço</label>
			    <div class="col-lg-10">
			      <input type="text" class="form-control" id="inputCrn1" name="paciente.endereco"  placeholder="Endereço" value="${flash['paciente.endereco']}">
			    </div>
  			</div>
  			<div class="form-group">
			    <label for="inputLogin1" class="col-lg-2 control-label">Bairro</label>
			    <div class="col-lg-10">
			      <input type="text" class="form-control" id="inputLogin1" name="paciente.bairro"  placeholder="Bairro" value="${flash['paciente.bairro']}">
			    </div>
  			</div>
  			<div class="form-group">
			    <label for="inputSenha1" class="col-lg-2 control-label">Cidade</label>
			    <div class="col-lg-10">
			      <input type="text" class="form-control" id="inputSenha1" name="paciente.cidade"  placeholder="Cidade" value="${flash['paciente.cidade']}">
			    </div>
  			</div>
         	
        </div>
        <div class="modal-footer">
          <a href="@{Administradores.index()}" type="button" class="btn btn-default" data-dismiss="modal">Cancelar</a>
          <button type="submit" class="btn btn-success" id="btn-save" onclick="return confirm('Confirma?')">Salvar</button>
        </div></form>
      </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->
  
  
  <div class="modal fade" id="mmmyModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">Calcular IMC</h4>
        </div>
        <form name="imc" class="form-horizontal" role="form" >
        <div class="modal-body">
         	
         		<div class="form-group">
			    <label for="inputNome1" class="col-lg-2 control-label">Peso</label>
			    
			    <div class="col-lg-5">
			      <input type="text" class="form-control" id="inputNome1" name="paciente.nome" placeholder="Peso" value="${flash['paciente.nome']}">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="inputCpf1" class="col-lg-2 control-label">Altura</label>
			    <div class="col-lg-5">
			      <input type="text" class="form-control" id="inputCpf1" name="paciente.cpf"  placeholder="Altura" value="${flash['paciente.cpf']}">
			    </div>
  			</div>
  			
         	
        </div>
        <div class="modal-footer">
          <a href="@{Administradores.index()}" type="button" class="btn btn-default" data-dismiss="modal">Cancelar</a>
          <button type="submit" class="btn btn-success" id="btn-save" onclick="teste()">Calcular</button>
        </div></form>
      </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->
  
  
  <script type="text/javascript">
  
  function teste(){
	  
	  var total, x, y;
	   x = document.imc.inputNome1.value;
	   y = document.imc.inputCpf1.value;
	 
	   total = x/(y*y);
	   

	   
	  	if(total<=18.5){
		   alert(total+" Abaixo do peso!");
	   }
	   else if(total>=18.6 & total<=24.9){
		   alert(total+" Saudável");
	   }
	   else if(total>=25 & total<=29.9){
		   alert(total+" Sobrepeso");
	   }
	   else if(total>=30 & total<=34.9){
		   alert(total+" Obesidade Grau I");
	   }
	   else if(total>=35 & total<=39.9){
		   alert(total+" Obesidade Grau II(Severa)");
	   }
	   else if(total>=40){
		   alert(total+" Obesidade Grau III(Mórbida)");
	   }
	  
	
  }
  
	    $("#mmmyModal").on('hidden.bs.modal', function(){
	    	
	    	
	    
	        alert("Modal window has been completely closed.");
	    });
	
</script>
